Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include tBTC reference in the Acre contract deployment scripts #58

Merged
merged 11 commits into from
Dec 7, 2023

Conversation

nkuba
Copy link
Member

@nkuba nkuba commented Dec 1, 2023

Depends on #52

Acre contract requires tBTC address as argument.
We add 00_resolve_tbtc.ts script that will ensure tBTC deployment
artifact reference is available based on the network.
For networks marked with allowStubs tag (hardhat local network for
running tests) a stub ERC20 contract will be deployed.

Added a script ./scripts/fetch_external_artifacts.sh that downloads
TBTC token deployment artifact from NPM packages for sepolia and mainnet
network and places them under ./external directory where they will be
used for contracts deployment.

@nkuba nkuba requested a review from r-czajkowski December 1, 2023 15:13
@nkuba nkuba self-assigned this Dec 1, 2023
@nkuba nkuba added the 🔗 Solidity Solidity contracts label Dec 1, 2023
@nkuba nkuba added this to the MVP milestone Dec 1, 2023
nkuba added 2 commits December 1, 2023 16:26
Acre contract requires tBTC address as argument.
We add `00_resolve_tbtc.ts` script that will ensure tBTC deployment
artifact reference is available based on the network.
For networks marked with `allowStubs` tag (hardhat local network for
running tests) a stub ERC20 contract will be deployed.
Added a script `./scripts/fetch_external_artifacts.sh` that downloads
TBTC token deployment artifact from NPM packages for sepolia and mainnet
network and places them under `./external` directory where they will be
used for contracts deployment.
Ownership of Acre contract will have to be transferred once Acre extends
Ownable.
@nkuba nkuba mentioned this pull request Dec 5, 2023
Base automatically changed from token-vault to main December 7, 2023 10:04
@nkuba nkuba marked this pull request as ready for review December 7, 2023 10:07
Removed `/`to be consistent with other items.
@nkuba nkuba requested a review from dimpar December 7, 2023 10:08
@nkuba nkuba requested a review from r-czajkowski December 7, 2023 10:34
import { ethers } from "ethers"

// eslint-disable-next-line import/prefer-default-export
export function isNonZeroAddress(address: string): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on replacing with:

export function isValidAddress(address: string): boolean {
  try {
    ethers.getAddress(address)
  } catch (e) {
    return false
  }

  if (ethers.getAddress(address) === ethers.ZeroAddress) {
    return false
  }

  return true
}

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean using the isValidAddress from @keep-network/hardhat-helpers or updating the implementation here?

@keep-network/hardhat-helpers is specific for @keep-network projects and is based on ethers v5.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, no need to reference keep-network. Just use the ethers lib and add/replace a check in if (tbtc && isNonZeroAddress(tbtc.address)) with if (tbtc && isValidAddress(tbtc.address)). It's just to validate that the address should not only be zero, but it's actually valid as well. ethers lib will check it.

Copy link
Contributor

@r-czajkowski r-czajkowski Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on replacing with:

export function isValidAddress(address: string): boolean {
  try {
    ethers.getAddress(address)
  } catch (e) {
    return false
  }

  if (ethers.getAddress(address) === ethers.ZeroAddress) {
    return false
  }

  return true
}

?

Instead of try catch we can use isAddress from ethers:

export function isValidAddress(address: string): boolean {
 return (
    ethers.isAddress(address) &&
    ethers.getAddress(address) !== ethers.ZeroAddress
  )
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call ethers.getAddress(address) !== ethers.ZeroAddress, so the address is validated with ethers.getAddress.

I added tests to ensure it works as expected: 332d6a9

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, then this function name is misleading a bit. It checks not only if the address is zero, but also other things.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the current name isNonZeroAddress. It describes what the function is used for: check if the address is a non-zero address.

#! /bin/bash
set -eou pipefail

ROOT_DIR="$(realpath "$(dirname $0)/../")"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the realpath an external or built-in function? After migrating to M2 this command doesn't work for me. If it's external we should mention how to install it in the README.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on M2 and this script worked for me. However, I did the auto-migration from my old Mac copying everything, so maybe it also copied realpath. It's located in /usr/local/bin/realpath on my box.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Works on my machine™

Updated in 3a05a45

core/scripts/fetch_external_artifacts.sh Outdated Show resolved Hide resolved
core/scripts/fetch_external_artifacts.sh Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking:

Maybe we should consider adding a prettier for sh files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#75

fetch_external_artifact "sepolia" "@keep-network/tbtc-v2" "TBTC"

# Remove downloaded NPM packages.
rm -rf ${TMP_DIR}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It removes tmp/external-artifacts, but leaves tmp. We should remove root tmp and all the subfolders.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally left the main ./tmp directory in case it contains files from other processes. We remove only the ./tmp/external-artifacts directory that contains files relevant to this script.
The main ./tmp was added to .gitignore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally left the main ./tmp directory in case it contains files from other processes.

Then how about adding -d flag to rm -d tmp? If it's non-empty then the command won't remove it. If empty, it will. Point is, this script can create a temporary dir on dev's box and if after running the script it's empty, then it will be nice to clean it as well. That's my final comment, if you think otherwise, leave it as-is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have strong feelings; I'd leave it as is for now and see if we find the current approach painful.
Please feel free to introduce any improvements to the script, though!

Copy link
Member

@dimpar dimpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few minor comments left but they can be addressed later to unblock other PRs

@dimpar dimpar merged commit b03d232 into main Dec 7, 2023
9 checks passed
@dimpar dimpar deleted the deploy-scripts branch December 7, 2023 11:47
nkuba added a commit that referenced this pull request Dec 8, 2023
As per #58 (comment)
realpath is not available out of the box on OSX. Instead of installing
additional package, we changed the way the path is resolved.
dimpar added a commit that referenced this pull request Dec 13, 2023
Depends on: #58

Improve test fixtures used in Acre contract tests:
- use Acre and TBTC contracts deployed with hardhat development scripts
(#58)
- use unnamed signers as stakers, to not overlap with named signers
defined in `hardhat.config.ts`. `ethers.getSigners()` returns all
signers, regardless of whether it is a Hardhat named or unnamed account

---
This PR contains changes from #62
which were unintentionally merged to this branch.
@nkuba nkuba mentioned this pull request Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔗 Solidity Solidity contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants